<template>
<div>
  <div style="margin-top: 80px">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }"><span class="text-article">首页</span></el-breadcrumb-item>
      <el-breadcrumb-item><span class="text-article">社团申请</span></el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <el-divider style="margin-left: 20%"></el-divider>
  <div style="width: 60%;height: 500px;margin-left: 20%;box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);border: 1px;">
    <div>
      <br/>
      <br/>
      <h2>申请表</h2>
      <span>学生姓名 &nbsp;&nbsp;</span>
      <el-input class="inputMax"  v-model="applicant.name" placeholder="请输入姓名"></el-input>
      <br/>
      <br/>
      <span>申请社团 &nbsp;&nbsp;</span>
      <el-select  placeholder="请选择" v-model="applicant.c_id" class="inputMax">
        <el-option
            v-for="club in clubs"
            :key="club.id"
            :label="club.name"
            :value="club.id"
        ></el-option>
      </el-select>
      <br/>
      <br/>
      <span>&nbsp;&nbsp;&nbsp;邮箱 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
      <el-input class="inputMax" v-model="applicant.email" placeholder="请输入邮箱"></el-input>
      <br/>
      <br/>
      <el-input
          type="textarea"
          :rows="2"
          style="width: 80%"
          placeholder="请输入申请内容"
          v-model="applicant.content"
      >
      </el-input>
      <br/>
      <br/>
      <el-button type="primary" @click="toApplicantInsert">提交</el-button>
    </div>
  </div>
</div>
</template>

<script>
import {clubListApi,applicantInsertApi} from '@/api'
export default {
  name: "ClubApplicant",
  data(){
    return {
      applicant: {
        name: '',
        content: '',
        email: '',
        c_id:'',
      },
      clubs:[],
    }
  },

  created() {
    clubListApi().then((result)=>{
      this.clubs = result.data.list;
    })
  },

  methods:{
    toApplicantInsert(){
      let applicant = this.applicant;
        if (applicant.name != '' && applicant.c_id !='' && applicant.email!='' && applicant.content!=''){
          applicantInsertApi(applicant);
          this.applicant = '';
          this.$message.success("提交成功");
        }else{
          this.$message.error('请填写完整');
        }
    }
  }
}
</script>

<style scoped>
.text-article{
  font-size: 1.5em;
}
.inputMax{
  width: 200px;
}
</style>
